package com.bbg.amyam.web.service.login;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;

public class LogoutLandingService extends SimpleUrlLogoutSuccessHandler  {

	@Override
	public void onLogoutSuccess(HttpServletRequest request,
			HttpServletResponse response, Authentication authentication)
			throws IOException, ServletException {
	
		String target = request.getParameter("_uname");
		target=target==null?"default":target;
		String viewName="school_public_view";
		if("default".equals(target)){
			viewName="public_view";
		}
		
		request.getSession(true).removeAttribute("_amyam_unit_name_");
		
		this.setAlwaysUseDefaultTargetUrl(true);
		setDefaultTargetUrl("/"+target+"/"+viewName);
		//super.setAlwaysUseDefaultTargetUrl(true);
		super.onLogoutSuccess(request, response, authentication);
		
	}

}
